package uk.ac.nott.cs.g53dia;
/**
 * Action to harvest energy from a clump of flowers.
 * <p>
 * To perform the action, the bee must be at the same location as the flowers.
 * 
 * @author Neil Madden
 */

/*
 * Copyright (c) 2005 Neil Madden.
 * Copyright (c) 2010 University of Nottingham.
 * 
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

public class HarvestAction implements Action {

    public HarvestAction() {}

    public void execute(Environment env, Bee bee) 
    throws ActionFailedException
    {
        Cell current = env.getCell(bee.getPosition());
        if (current instanceof Flower) {
            int amount = ((Flower)current).collect(env.getTimestep());
            if (bee.energy + amount > Bee.MAX_ENERGY) {
                // Cap bee energy capacity
                bee.energy = Bee.MAX_ENERGY;
            } else {
                bee.energy += amount;
            }
        } else {
            throw new ActionFailedException("Harvest: Not on a flower");
        }
    }

    public String toString() {
        return "Harvest flower";
    }
}
